# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/24 11:51 
@Author  : ZhangShenao 
@File    : custom_exception.py
@Desc    : 自定义业务异常
"""
from dataclasses import field
from typing import Any

from pkg.response import HttpStatusCode


class CustomException(Exception):
    """自定义业务异常"""
    code: HttpStatusCode = HttpStatusCode.FAIL
    message: str = ""
    data: Any = field(default_factory=dict)

    def __init__(self, message: str = None, data: Any = None):
        super().__init__()
        self.message = message
        self.data = data


class FailException(CustomException):
    """通用失败异常"""
    pass


class NotFoundException(CustomException):
    """未找到资源异常"""
    code = HttpStatusCode.NOT_FOUND


class UnauthorizedException(CustomException):
    """未授权异常"""
    code = HttpStatusCode.UNAUTHORIZED


class ForbiddenException(CustomException):
    """无权限异常"""
    code = HttpStatusCode.FORBIDDEN


class ValidateErrorException(CustomException):
    """数据验证异常"""
    code = HttpStatusCode.VALIDATE_ERROR
